﻿using System;

namespace TEST03
{
    class Program
    {

       


        static void Main(string[] args)
        {
            #region
            //定义二维数组
            //int[,] arr = new int[,] { {1,2,3 }, {4,5,6 }, {7,8,9 } };
            ////对角元素之和
            //int sum = 0;
            //for(int i = 0; i < arr.GetLength(0); i++)
            //{
            //    for(int j = 0; j < arr.GetLength(1); j++)
            //    {
            //        if (i == j)
            //        {
            //            sum += arr[i, j];
            //        }
            //    }
            //}
            //Console.WriteLine("sum={0}",sum);
            #endregion

            // 11.用户输入整数n，计算1! + (1! + 2!) + (1! + 2! + 3!) +…..+(1! + 2! +…n!)
            //1.求n！
            //2.求(1! + 2! +…n!)
            //  fac(1)+fac(2)+...+fac(n)
            //1!+2!+3!+4! = 
            //fac(1) + fac(2) + fac(3) + fac(4);
            //int sum = 0;
            //for(int i = 1; i <= n; i++)
            //{
            //    sum += fac(i);
            //}



            // //1.   5! = 5*4*3*2*1
            Console.WriteLine("请输入n:");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(a(n));
        }
        //n!
        static int fac(int n)
        {
            int acc = 1;
            for (int i = 1; i <= n; i++)
            {
                acc *= i;
            }
            return acc;
        }

        //2.求阶乘的和
        static int sumFac(int n)
        {
            int sum = 0;
            for (int i = 1; i <= n; i++)
            {
                sum += fac(i);
            }
            return sum;
        }
        //3.求suamFac(1) + sumFac(2) + sumFac(3) +…..+sumFac(n)
        static int a(int n)
        {
            int a1 = 0;
            for (int i = 1; i <= n; i++)
            {
                a1 += sumFac(i);
            }
            return a1;
        }
    }
}
